home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1993 / MacHack 1993.toast / MacHack™ 1987-1992 / MacHack™ '87 / Source ƒ / Pascal ƒ / Pascal utils / Utilities.pas next >
Encoding:
Pascal/Delphi Source File  |  1987-01-06  |  20.9 KB  |  775 lines  |  [TEXT/MPS ]

  1. unit Utilities;
  2.  
  3.     {$R-}
  4.     { No range checking  }
  5.  
  6.     interface
  7.  
  8.         uses ROM85, SANE;
  9.  
  10.         const
  11.             {Useful MacConstants}
  12.             BtnControlOff = 0;
  13.             BtnControlOn = 1;
  14.             DefaultItem = 1;
  15.             Margin5 = 5;
  16.             Margin16 = 16;
  17.             ScrollBarSize = Margin16;
  18.             WindowTitle = 18;
  19.             MenuBarSize = 20;
  20.             EighthSecond = 8;
  21.             QuarterSecond = 15;
  22.             HalfSecond = 30;
  23.             OneSecond = 60;
  24.             NewRomsID = 117;
  25.             DeadControl = 255;
  26.             TESelStart = 0;
  27.             TESelEnd = 32767;
  28.             TooMuch = 16777216;
  29.  
  30.             {Useful Mac Key code constants}
  31.             ETX = $03; {Enter Key}
  32.             EnterKey = ETX;
  33.             BS = $08; {BackSpace Key}
  34.             CR = $0D; {Return Key}
  35.             ReturnKey = CR;
  36.             HT = $09; {TAB Key}
  37.             TabKey = HT;
  38.             ESC = $1B; {Escape Key}
  39.             FS = $1C; {Left arrow key}
  40.             LeftArrow = FS;
  41.             GS = $1D; {Right arrow key}
  42.             RightArrow = GS;
  43.             RS = $1E; {Up arrow key}
  44.             UpArrow = RS;
  45.             US = $1F; {Down arrow key}
  46.             DownArrow = US;
  47.             EndofLine = $7F; {End of Line Delimeter}
  48.             NoBrkSpace = $CA; {None Breaking space for Mono Spacing}
  49.  
  50.             {Utility Dialog Constants}
  51.             YesNoCancelID = 1966;
  52.             YesButton = 1;
  53.             CancelButton = 2;
  54.             NoButton = 3;
  55.             StaticText = 4;
  56.  
  57.         type
  58.             GenericResponse = (nullResponse, YesResponse, CancelResponse, NoResponse);
  59.  
  60.         var
  61.             theDialogFilter: ProcPtr;
  62.             ScreenSize: Rect;
  63.  
  64.         procedure StandardInit;
  65.         function GetEven(theNum: LONGINT): LONGINT;
  66.         function EnumValue(theValue: INTEGER): SignedByte;
  67.         function GetRectSize(theRect: Rect): Point;
  68.         function NewRoms: BOOLEAN;
  69.         function HFSRunning: BOOLEAN;
  70.         function OptKeyDown(theModifiers: INTEGER): BOOLEAN;
  71.         function CapsLockDown(theModifiers: INTEGER): BOOLEAN;
  72.         function ShiftKeyDown(theModifiers: INTEGER): BOOLEAN;
  73.         function CmdKeyDown(theModifiers: INTEGER): BOOLEAN;
  74.         function WindowActivate(theModifiers: INTEGER): BOOLEAN;
  75.         procedure CenterInRect(var theRect: Rect;
  76.                                                      theCenterRect: Rect;
  77.                                                      vOffSet, hOffSet: INTEGER);
  78.         procedure CenterInScreen(var theRect: Rect;
  79.                                                          vOffSet, hOffSet: INTEGER);
  80.         function GetWindowKind(theWindow: WindowPtr): INTEGER;
  81.         function FrontSysWindow: BOOLEAN;
  82.         function CenterNewWindow(theWindowID: INTEGER;
  83.                                                          wStorage: Ptr;
  84.                                                          behind: WindowPtr;
  85.                                                          vOffSet, hOffSet: INTEGER): WindowPtr;
  86.         procedure ToggleButton(theControl: ControlHandle);
  87.         procedure SetButtonGroup(theDialog: DialogPtr;
  88.                                                          theFirstButton, theLastButton, theButton: INTEGER);
  89.         function GetSetButton(theDialog: DialogPtr;
  90.                                                     theFirstButton, theLastButton: INTEGER): INTEGER;
  91.         procedure SelEditText(theDialog: DialogPtr;
  92.                                                     theItem: INTEGER);
  93.         procedure SetEditText(theDialog: DialogPtr;
  94.                                                     theItem: INTEGER;
  95.                                                     var theText: str255);
  96.         function GetEditText(theDialog: DialogPtr;
  97.                                                  theItem: INTEGER): str255;
  98.         procedure SetEditReal(theDialog: DialogPtr;
  99.                                                     theItem: INTEGER;
  100.                                                     theNumber: Extended;
  101.                                                     theForm: DecForm);
  102.         function GetEditReal(theDialog: DialogPtr;
  103.                                                  theItem: INTEGER;
  104.                                                  var theNumber: Extended): BOOLEAN;
  105.         function DoSFGet(theFileCount: INTEGER;
  106.                                          theTypeList: SFTypeList;
  107.                                          vOffSet, hOffSet: INTEGER): SFReply;
  108.         function DoSFPut(var theSavePrompt, OrigFileName: str255;
  109.                                          vOffSet, hOffSet: INTEGER): SFReply;
  110.         function CenterNewDialog(theDialogID: INTEGER;
  111.                                                          dStorage: Ptr;
  112.                                                          behind: WindowPtr;
  113.                                                          vOffSet, hOffSet: INTEGER): DialogPtr;
  114.         procedure OutLineButton(thePort: GrafPtr;
  115.                                                         theRect: Rect);
  116.         procedure DialogDefault(theDialog: DialogPtr);
  117.         procedure SetupDialog(theDialog: DialogPtr;
  118.                                                     ButtonKeys, CheckBoxKeys, RadioKeys: BOOLEAN);
  119.         procedure DisposSetUp(theDialog: DialogPtr);
  120.         function GetDLOGRefCon(theDialog: DialogPtr): LONGINT;
  121.         function YesNoCancelDLOG(var parm0, parm1, parm2,
  122.                                                          parm3: str255): GenericResponse;
  123.         function YesNoDLOG(var parm0, parm1, parm2, parm3: str255): GenericResponse;
  124.         function DeleteFile: BOOLEAN;
  125.  
  126.     implementation
  127.  
  128.         const
  129.             ButtonItem = 4;
  130.             CheckBox = 5;
  131.             RadioButton = 6;
  132.  
  133.         type
  134.             str1 = STRING[1];
  135.             KeyReplaceRec = record
  136.                 Key: str1;
  137.                 Item: INTEGER;
  138.                 end; {record KeyReplace}
  139.             KeyReplacePtr = ^KeyReplaceRec;
  140.             KeyReplaceHDL = ^KeyReplacePtr;
  141.  
  142.             KeyListArray = array [1..1] of KeyReplaceRec;
  143.             KeyListPtr = ^KeyListArray;
  144.             KeyListHDL = ^KeyListPtr;
  145.  
  146.             KeyListRec = record
  147.                 ListHDL: KeyListHDL;
  148.                 ListCount, LastItem: INTEGER;
  149.                 OldRefCon, LastTime: LONGINT;
  150.                 end; {record KeyListRec}
  151.             KeyListRecPtr = ^KeyListRec;
  152.             KeyListRecHDL = ^KeyListRecPtr;
  153.  
  154.             DLOGHeaderRec = record
  155.                 ItemCount: INTEGER;
  156.                 end; {DLOGHeader}
  157.             DLOGHeaderPtr = ^DLOGHeaderRec;
  158.             DLOGHeaderHDL = ^DLOGHeaderPtr;
  159.  
  160.         procedure ResumeProgram;
  161.             begin
  162.                 ExitToShell;
  163.             end; {ResumeProgram}
  164.  
  165.         procedure StandardInit;
  166.             var
  167.                 Screen_Width, Screen_Height: INTEGER;
  168.             begin
  169.                 InitGraf(@thePort);
  170.                 InitFonts;
  171.                 InitWindows;
  172.                 InitMenus;
  173.                 TEInit;
  174.                 InitDialogs(@ResumeProgram);
  175.                 InitCursor;
  176.                 InitAllPacks;
  177.  
  178.                 Screen_Width:=screenbits.bounds.right;
  179.                 Screen_Height:=screenbits.bounds.bottom;
  180.                 SetRect(ScreenSize, 0, MenuBarSize, Screen_Width, Screen_Height);
  181.                 InsetRect(ScreenSize, Margin5, Margin5);
  182.  
  183.                 theDialogFilter:=nil;
  184.             end; {Initalize}
  185.  
  186.         function GetEven;
  187.             begin
  188.                 if ODD(theNum) then
  189.                     theNum:=SUCC(theNum)
  190.                 else
  191.                     GetEven:=theNum;
  192.             end; {Get_Even}
  193.  
  194.         function EnumValue;
  195.             begin
  196.                 EnumValue:=theValue;
  197.             end; {EnumValue}
  198.  
  199.         function NewRoms;
  200.             var
  201.                 RomVersion, Machine: INTEGER;
  202.             begin
  203.                 Environs(RomVersion, Machine);
  204.                 NewRoms:=RomVersion>=NewRomsID;
  205.             end; {NewRoms}
  206.  
  207.         function HFSRunning;
  208.             const
  209.                 FSFCBLen = $3F6;
  210.             var
  211.                 HFS: ^INTEGER;
  212.             begin
  213.                 HFS:=POINTER(FSFCBLen);
  214.                 HFSRunning:=(HFS^>0);
  215.             end; {HFSRunning}
  216.  
  217.         function OptKeyDown;
  218.             begin
  219.                 OptKeyDown:=BitAnd(theModifiers, optionKey)>0;
  220.             end; {OptKeyDown}
  221.  
  222.         function CapsLockDown;
  223.             begin
  224.                 CapsLockDown:=BitAnd(theModifiers, alphaLock)>0;
  225.             end; {CapsLockDown}
  226.  
  227.         function ShiftKeyDown;
  228.             begin
  229.                 ShiftKeyDown:=BitAnd(theModifiers, shiftKey)>0;
  230.             end; {ShiftKeyDown}
  231.  
  232.         function CmdKeyDown;
  233.             begin
  234.                 CmdKeyDown:=BitAnd(theModifiers, cmdKey)>0;
  235.             end; {CmdKeyDown}
  236.  
  237.         function WindowActivate;
  238.             begin
  239.                 WindowActivate:=BitAnd(theModifiers, activeFlag)>0;
  240.             end; {WindowActivate}
  241.  
  242.         function GetRectSize;
  243.             var
  244.                 TempPoint: Point;
  245.             begin
  246.                 TempPoint.v:=theRect.bottom-theRect.top;
  247.                 TempPoint.h:=theRect.right-theRect.left;
  248.                 GetRectSize:=TempPoint;
  249.             end; {GetRectSize}
  250.  
  251.         procedure CenterInRect;
  252.             var
  253.                 RectSize: Point;
  254.             begin
  255.                 {Calculate the Width and Height of the Display Rectangle}
  256.                 RectSize:=GetRectSize(theRect);
  257.  
  258.                 {Center the Display Rect in the CenterRect}
  259.                 theRect.top:=ROUND(theCenterRect.bottom/2)-ROUND(RectSize.v/2);
  260.                 theRect.left:=ROUND(theCenterRect.right/2)-ROUND(RectSize.h/2);
  261.  
  262.                 {Offset the Display Rect by the Requested Amount}
  263.                 theRect.top:=theRect.top+vOffSet;
  264.                 theRect.left:=theRect.left+hOffSet;
  265.  
  266.                 {Move the Bottom Right to the new Position for Centering}
  267.                 theRect.bottom:=theRect.top+RectSize.v;
  268.                 theRect.right:=theRect.left+RectSize.h;
  269.             end; {CenterInRect}
  270.  
  271.         procedure CenterInScreen;
  272.             var
  273.                 TempRect: Rect;
  274.             begin
  275.                 TempRect:=screenbits.bounds;
  276.                 TempRect.top:=TempRect.top+SUCC(MenuBarSize);
  277.                 CenterInRect(theRect, TempRect, vOffSet, hOffSet);
  278.             end; {Center_Rect}
  279.  
  280.         function GetWindowKind;
  281.             var
  282.                 TempWindow: WindowPeek;
  283.             begin
  284.                 TempWindow:=WindowPeek(theWindow);
  285.                 GetWindowKind:=TempWindow^.windowKind;
  286.             end; {Get_WindowKind}
  287.  
  288.         function FrontSysWindow;
  289.             begin
  290.                 if FrontWindow<>nil then
  291.                     FrontSysWindow:=(GetWindowKind(FrontWindow)<0)
  292.                 else
  293.                     FrontSysWindow:=FALSE;
  294.             end; {Front_SysWindow}
  295.  
  296.         function CenterNewWindow;
  297.             var
  298.                 Window: WindowPtr;
  299.                 WindowRect: Rect;
  300.             begin
  301.                 Window:=GetNewWindow(theWindowID, wStorage, behind);
  302.                 WindowRect:=Window^.portRect;
  303.                 CenterInScreen(WindowRect, vOffSet, hOffSet);
  304.                 MoveWindow(Window, WindowRect.left, WindowRect.top, TRUE);
  305.                 CenterNewWindow:=Window;
  306.             end; {CenterNewWindow}
  307.  
  308.         function DoSFGet;
  309.             var
  310.                 TempDialog: DialogPtr;
  311.                 TempReply: SFReply;
  312.                 TempRect: Rect;
  313.                 Corner: Point;
  314.             begin
  315.                 TempDialog:=GetNewDialog(getDlgID, nil, nil);
  316.                 TempRect:=TempDialog^.portRect;
  317.                 CenterInScreen(TempRect, vOffSet, hOffSet);
  318.                 DisposDialog(TempDialog);
  319.                 Corner.v:=TempRect.top;
  320.                 Corner.h:=TempRect.left;
  321.  
  322.                 SFGetFile(Corner, '', nil, theFileCount, theTypeList, nil, TempReply);
  323.                 DoSFGet:=TempReply;
  324.             end; {Do_SFGet}
  325.  
  326.         function DoSFPut;
  327.             var
  328.                 TempDialog: DialogPtr;
  329.                 TempReply: SFReply;
  330.                 TempRect: Rect;
  331.                 Corner: Point;
  332.             begin
  333.                 TempDialog:=GetNewDialog(putDlgID, nil, nil);
  334.                 TempRect:=TempDialog^.portRect;
  335.                 CenterInScreen(TempRect, vOffSet, hOffSet);
  336.                 DisposDialog(TempDialog);
  337.                 Corner.h:=TempRect.left;
  338.                 Corner.v:=TempRect.top;
  339.  
  340.                 SFPutFile(Corner, theSavePrompt, OrigFileName, nil, TempReply);
  341.                 DoSFPut:=TempReply;
  342.             end; {Do_SFPut}
  343.  
  344.         procedure ToggleButton;
  345.             begin
  346.                 SetCtlValue(theControl, SUCC(-(GetCtlValue(theControl))));
  347.             end; {ToggleButton}
  348.  
  349.         procedure SetButtonGroup;
  350.             var
  351.                 ItemRect: Rect;
  352.                 ItemHDL: Handle;
  353.                 ControlHDL: ControlHandle;
  354.                 ItemType, Loop: INTEGER;
  355.             begin
  356.                 for Loop:=theFirstButton to theLastButton do
  357.                     begin
  358.                         GetDItem(theDialog, Loop, ItemType, ItemHDL, ItemRect);
  359.                         ControlHDL:=ControlHandle(ItemHDL);
  360.                         if Loop<>theButton then
  361.                             begin
  362.                                 if GetCtlValue(ControlHDL)>0 then ToggleButton(ControlHDL);
  363.                             end {if Loop <> theButton}
  364.                         else if GetCtlValue(ControlHDL)=0 then ToggleButton(ControlHDL);
  365.                     end; {for Loop := theFirstButton to theLastButton}
  366.             end; {SetButtonGroup}
  367.  
  368.         function GetSetButton;
  369.             var
  370.                 ItemRect: Rect;
  371.                 ItemHDL: Handle;
  372.                 ControlHDL: ControlHandle;
  373.                 ItemType, Loop: INTEGER;
  374.             begin
  375.                 GetSetButton:=0;
  376.                 for Loop:=theFirstButton to theLastButton do
  377.                     begin
  378.                         GetDItem(theDialog, Loop, ItemType, ItemHDL, ItemRect);
  379.                         ControlHDL:=ControlHandle(ItemHDL);
  380.                         if GetCtlValue(ControlHDL)>0 then GetSetButton:=Loop;
  381.                     end; {for Loop := theFirstButton to theLastButton}
  382.             end; {GetSetButton}
  383.  
  384.         procedure SelEditText;
  385.             var
  386.                 ItemRect: Rect;
  387.                 ItemHDL: Handle;
  388.                 ItemType: INTEGER;
  389.             begin
  390.                 GetDItem(theDialog, theItem, ItemType, ItemHDL, ItemRect);
  391.                 SelIText(theDialog, theItem, TESelStart, TESelEnd)
  392.             end; {SetEditText}
  393.  
  394.         procedure SetEditText;
  395.             var
  396.                 ItemRect: Rect;
  397.                 ItemHDL: Handle;
  398.                 ItemType: INTEGER;
  399.             begin
  400.                 GetDItem(theDialog, theItem, ItemType, ItemHDL, ItemRect);
  401.                 SetIText(ItemHDL, theText);
  402.             end; {SetEditText}
  403.  
  404.         function GetEditText;
  405.             var
  406.                 ItemStr: str255;
  407.                 ItemRect: Rect;
  408.                 ItemHDL: Handle;
  409.                 ItemType: INTEGER;
  410.             begin
  411.                 GetDItem(theDialog, theItem, ItemType, ItemHDL, ItemRect);
  412.                 GetItext(ItemHDL, ItemStr);
  413.                 GetEditText:=ItemStr;
  414.             end; {GetEditText}
  415.  
  416.         procedure SetEditReal;
  417.             var
  418.                 NumberStr: DecStr;
  419.             begin
  420.                 Num2Str(theForm, theNumber, NumberStr);
  421.                 SetEditText(theDialog, theItem, NumberStr);
  422.             end; {SetEditReal}
  423.  
  424.         function GetEditReal;
  425.             var
  426.                 NumberStr: str255;
  427.                 TempReal: Extended;
  428.                 LegalDigits: set of CHAR;
  429.                 Loop: INTEGER;
  430.                 GoodNumber: BOOLEAN;
  431.             begin
  432.                 LegalDigits:=(['0'..'9', '.', '-']);
  433.                 NumberStr:=GetEditText(theDialog, theItem);
  434.  
  435.                 TempReal:=Str2Num(NumberStr);
  436.                 GoodNumber:=TRUE;
  437.                 for Loop:=1 to Length(NumberStr) do
  438.                     GoodNumber:=GoodNumber and (NumberStr[Loop] in LegalDigits);
  439.                 if GoodNumber then theNumber:=TempReal;
  440.  
  441.                 GetEditReal:=GoodNumber;
  442.             end; {GetEditReal}
  443.  
  444.         function KeyMatch(theListRecHDL: KeyListRecHDL;
  445.                                             theCharacter: str1): INTEGER;
  446.             var
  447.                 TempStr1, TempStr2: str255;
  448.                 Loop: INTEGER;
  449.             begin
  450.                 KeyMatch:=0;
  451.                 TempStr1:=theCharacter;
  452.                 for Loop:=1 to theListRecHDL^^.ListCount do
  453.                     begin
  454.                         TempStr2:=theListRecHDL^^.ListHDL^^[Loop].Key;
  455.                         if EqualString(TempStr1, TempStr2, FALSE, FALSE) then
  456.                             KeyMatch:=Loop;
  457.                     end; {for Loop := 1 to theListRecHDL^^.ListCount}
  458.             end; {KeyMatch}
  459.  
  460.         procedure AddKey(theListRecHDL: KeyListRecHDL;
  461.                                          theControl: ControlHandle;
  462.                                          theItemNumber: INTEGER);
  463.             var
  464.                 TempKey: KeyReplaceRec;
  465.                 ControlTitle: str255;
  466.                 ByteCount: LONGINT;
  467.             begin
  468.                 GetCTitle(theControl, ControlTitle);
  469.  
  470.                 if KeyMatch(theListRecHDL, Copy(ControlTitle, 1, 1))=0 then
  471.                     begin
  472.                         TempKey.Key:=Copy(ControlTitle, 1, 1);
  473.                         TempKey.Item:=theItemNumber;
  474.  
  475.                         theListRecHDL^^.ListCount:=SUCC(theListRecHDL^^.ListCount);
  476.                         ByteCount:=GetEven(SIZEOF(KeyReplaceRec))*theListRecHDL^^.ListCount;
  477.  
  478.                         if theListRecHDL^^.ListHDL=nil then
  479.                             theListRecHDL^^.ListHDL:=KeyListHDL(NewHandle(ByteCount))
  480.                         else
  481.                             SetHandleSize(Handle(theListRecHDL^^.ListHDL), ByteCount);
  482.  
  483.                         theListRecHDL^^.ListHDL^^[theListRecHDL^^.ListCount]:=TempKey;
  484.                     end; {if KeyMatch(theListRecHDL, ControlTitle[1]) = 0}
  485.             end; {AddKey}
  486.  
  487.         function DoDialogMouse(theListHDL: KeyListRecHDL;
  488.                                                      theDialog: DialogPtr;
  489.                                                      theEvent: EventRecord;
  490.                                                      var theItem: INTEGER): BOOLEAN;
  491.             var
  492.                 SavePort: GrafPtr;
  493.                 ControlHDL: ControlHandle;
  494.                 ItemHDL: Handle;
  495.                 ItemRect: Rect;
  496.                 LocalPoint: Point;
  497.                 ItemType, ControlPart: INTEGER;
  498.             begin
  499.                 DoDialogMouse:=FALSE;
  500.                 GetPort(SavePort);
  501.                 SetPort(theDialog);
  502.  
  503.                 LocalPoint:=theEvent.where;
  504.                 GlobaltoLocal(LocalPoint);
  505.                 ControlPart:=FindControl(LocalPoint, theDialog, ControlHDL);
  506.                 if ControlPart<>0 then
  507.                     begin
  508.                         theItem:=FindDItem(theDialog, LocalPoint);
  509.                         theItem:=SUCC(theItem);
  510.                         if theItem>0 then
  511.                             begin
  512.                                 GetDItem(theDialog, theItem, ItemType, ItemHDL, ItemRect);
  513.                                 if ItemType=RadioButton then
  514.                                     begin
  515.                                         if theItem=theListHDL^^.LastItem then
  516.                                             begin
  517.                                                 if (theEvent.when-theListHDL^^.LastTime)<=
  518.                                                      GetDblTime then
  519.                                                     begin
  520.                                                         theItem:=1;
  521.                                                         DoDialogMouse:=TRUE;
  522.                                                     end; {if (theEvent.when - theListHDL^^.LastTime) <=
  523.                                                                 GetDblTime}
  524.                                             end; {if theItem = theListHDL^^.LastItem}
  525.  
  526.                                         theListHDL^^.LastItem:=theItem;
  527.                                         theListHDL^^.LastTime:=theEvent.when;
  528.                                     end; {if (ItemType = RadioButton)}
  529.                             end; {if theItem > 0}
  530.                     end; {if ControlPart <> 0}
  531.                 SetPort(SavePort);
  532.             end; {DoDialogMouse}
  533.  
  534.         function DoDialogKeyDown(theListHDL: KeyListRecHDL;
  535.                                                          theDialog: DialogPtr;
  536.                                                          theEvent: EventRecord;
  537.                                                          var theItem: INTEGER): BOOLEAN;
  538.             var
  539.                 theCharacter: str1;
  540.                 Index: INTEGER;
  541.             begin
  542.                 theItem:=0;
  543.                 DoDialogKeyDown:=FALSE;
  544.                 theCharacter:=' ';
  545.                 theCharacter[1]:=CHR(BitAnd(theEvent.message, charCodeMask));
  546.                 if (ORD(theCharacter[1])=CR) or (ORD(theCharacter[1])=ETX) then
  547.                     begin
  548.                         theItem:=1;
  549.                         DoDialogKeyDown:=TRUE;
  550.                     end {if ORD(theCharacter[1]) = CR or ORD(theCharacter[1]) = ETX}
  551.                 else
  552.                     begin
  553.                         if CmdKeyDown(theEvent.modifiers) then
  554.                             begin
  555.                                 Index:=KeyMatch(theListHDL, theCharacter);
  556.                                 if Index<>0 then
  557.                                     begin
  558.                                         theItem:=theListHDL^^.ListHDL^^[Index].Item;
  559.                                         DoDialogKeyDown:=TRUE;
  560.                                     end; {if Index <> 0}
  561.                             end; {if (CharModifers > 0) and ...}
  562.                     end; {else}
  563.             end; {DoDialogKeyDown}
  564.  
  565.         function CenterNewDialog;
  566.             var
  567.                 Dialog: DialogPtr;
  568.                 DialogRect: Rect;
  569.             begin
  570.                 Dialog:=GetNewDialog(theDialogID, dStorage, behind);
  571.                 DialogRect:=Dialog^.portRect;
  572.                 CenterInScreen(DialogRect, vOffSet, hOffSet);
  573.                 MoveWindow(Dialog, DialogRect.left, DialogRect.top, TRUE);
  574.                 CenterNewDialog:=Dialog;
  575.             end; {CenterNewDialog}
  576.  
  577.         procedure OutLineButton;
  578.             var
  579.                 OldPenState: PenState;
  580.                 SavePort: GrafPtr;
  581.             begin
  582.                 GetPort(SavePort);
  583.                 SetPort(thePort);
  584.                 GetPenState(OldPenState);
  585.                 PenSize(3, 3);
  586.                 InsetRect(theRect, -4, -4);
  587.                 FrameRoundRect(theRect, 16, 16);
  588.                 SetPenState(OldPenState);
  589.                 SetPort(SavePort);
  590.             end; {OutLineRect}
  591.  
  592.         procedure DialogDefault;
  593.             var
  594.                 ItemHDL: Handle;
  595.                 ItemRect: Rect;
  596.                 ItemType: INTEGER;
  597.             begin
  598.                 if theDialog<>nil then
  599.                     begin
  600.                         GetDItem(theDialog, DefaultItem, ItemType, ItemHDL, ItemRect);
  601.                         OutLineButton(theDialog, ItemRect);
  602.                     end; {if theDialog <> nil}
  603.             end; {DialogDefault}
  604.  
  605.         function DialogFilter(theDialog: DialogPtr;
  606.                                                     var theEvent: EventRecord;
  607.                                                     var theItem: INTEGER): BOOLEAN;
  608.             var
  609.                 ListRecHDL: KeyListRecHDL;
  610.                 ItemHandle: Handle;
  611.                 ControlHDL: ControlHandle;
  612.                 ItemRect: Rect;
  613.                 ItemType: INTEGER;
  614.                 RealDelay: LONGINT;
  615.                 MyItem: BOOLEAN;
  616.             begin
  617.                 DialogFilter:=FALSE;
  618.                 MyItem:=FALSE;
  619.                 ListRecHDL:=KeyListRecHDL(GetWRefCon(theDialog));
  620.                 if ListRecHDL<>nil then
  621.                     case theEvent.what of
  622.                         mouseDown, mouseUp:
  623.                             MyItem:=DoDialogMouse(ListRecHDL, theDialog, theEvent, theItem);
  624.  
  625.                         keyDown, autoKey:
  626.                             MyItem:=DoDialogKeyDown(ListRecHDL, theDialog, theEvent, theItem);
  627.                     end; {case theEvent.what}
  628.  
  629.                 if MyItem then
  630.                     begin
  631.                         GetDItem(theDialog, theItem, ItemType, ItemHandle, ItemRect);
  632.                         ControlHDL:=ControlHandle(ItemHandle);
  633.                         MyItem:=(MyItem) and (ControlHDL^^.contrlHilite<>DeadControl);
  634.                         if MyItem then
  635.                             begin
  636.                                 HiliteControl(ControlHandle(ItemHandle), BtnControlOn);
  637.                                 Delay(EighthSecond, RealDelay);
  638.                                 HiliteControl(ControlHandle(ItemHandle), BtnControlOff);
  639.                                 DialogFilter:=TRUE;
  640.                             end; {if MyItem}
  641.                     end; {if MyItem}
  642.             end; {DialogFilter}
  643.  
  644.         procedure SetupDialog;
  645.             var
  646.                 ListRecHDL: KeyListRecHDL;
  647.                 ItemHDL: Handle;
  648.                 ControlHDL: ControlHandle;
  649.                 DialogRecPtr: DialogPeek;
  650.                 DialogHDR: DLOGHeaderHDL;
  651.                 ItemRect: Rect;
  652.                 ItemType, ItemCnt, Loop: INTEGER;
  653.             begin
  654.                 if NewRoms then
  655.                     begin
  656.                         theDialogFilter:=@DialogFilter;
  657.                         ListRecHDL:=KeyListRecHDL(NewHandle(SIZEOF(KeyListRec)));
  658.                         with ListRecHDL^^ do
  659.                             begin
  660.                                 ListHDL:=nil;
  661.                                 ListCount:=0;
  662.                                 LastItem:=0;
  663.                                 OldRefCon:=GetWRefCon(theDialog);
  664.                                 LastTime:=0;
  665.                             end; {with ListRectHDL^^}
  666.  
  667.                         DialogRecPtr:=DialogPeek(theDialog);
  668.                         DialogHDR:=DLOGHeaderHDL(DialogRecPtr^.Items);
  669.                         ItemCnt:=DialogHDR^^.ItemCount;
  670.                         ItemCnt:=SUCC(ItemCnt);
  671.  
  672.                         for Loop:=1 to ItemCnt do
  673.                             begin
  674.                                 GetDItem(theDialog, Loop, ItemType, ItemHDL, ItemRect);
  675.                                 ControlHDL:=ControlHandle(ItemHDL);
  676.                                 case ItemType of
  677.                                     ButtonItem:
  678.                                         if ButtonKeys then AddKey(ListRecHDL, ControlHDL, Loop);
  679.                                     CheckBox:
  680.                                         if CheckBoxKeys then AddKey(ListRecHDL, ControlHDL, Loop);
  681.                                     RadioButton:
  682.                                         if RadioKeys then AddKey(ListRecHDL, ControlHDL, Loop);
  683.                                 end; {case ItemType}
  684.                             end; {for Loop := 1 to ItemCnt}
  685.  
  686.                         SetWRefCon(theDialog, LONGINT(ListRecHDL));
  687.                     end {if NewRoms}
  688.                 else
  689.                     theDialogFilter:=nil;
  690.             end; {SetupDialog}
  691.  
  692.         procedure DisposSetUp;
  693.             var
  694.                 ListRecHDL: KeyListRecHDL;
  695.                 RefCon: LONGINT;
  696.             begin
  697.                 ListRecHDL:=KeyListRecHDL(GetWRefCon(theDialog));
  698.                 RefCon:=ListRecHDL^^.OldRefCon;
  699.                 if ListRecHDL^^.ListHDL<>nil then
  700.                     DisposHandle(Handle(ListRecHDL^^.ListHDL));
  701.  
  702.                 DisposHandle(Handle(ListRecHDL));
  703.                 SetWRefCon(theDialog, RefCon);
  704.             end; {DisposSetup}
  705.  
  706.         function GetDLOGRefCon;
  707.             var
  708.                 KeyHandle: KeyListRecHDL;
  709.             begin
  710.                 KeyHandle:=KeyListRecHDL(GetWRefCon(theDialog));
  711.                 GetDLOGRefCon:=KeyHandle^^.OldRefCon;
  712.             end; {GetDLOGRefCon}
  713.  
  714.         function YesNoCancelDLOG;
  715.             var
  716.                 Dialog: DialogPtr;
  717.                 Item: INTEGER;
  718.             begin
  719.                 ParamText(parm0, parm1, parm2, parm3);
  720.                 Dialog:=CenterNewDialog(YesNoCancelID, nil, POINTER(-1), -50, 0);
  721.                 ShowWindow(Dialog);
  722.                 DialogDefault(Dialog);
  723.                 SetupDialog(Dialog, TRUE, TRUE, TRUE);
  724.                 ModalDialog(theDialogFilter, Item);
  725.                 DisposSetUp(Dialog);
  726.                 DisposDialog(Dialog);
  727.                 YesNoCancelDLOG:=GenericResponse(EnumValue(Item));
  728.             end; {YesNoCancelDLOG}
  729.  
  730.         function YesNoDLOG;
  731.             var
  732.                 Dialog: DialogPtr;
  733.                 ItemHDL: Handle;
  734.                 ControlHDL: ControlHandle;
  735.                 ItemRect: Rect;
  736.                 Item: INTEGER;
  737.             begin
  738.                 ParamText(parm0, parm1, parm2, parm3);
  739.                 Dialog:=CenterNewDialog(YesNoCancelID, nil, POINTER(-1), -50, 0);
  740.                 ShowWindow(Dialog);
  741.                 GetDItem(Dialog, CancelButton, Item, ItemHDL, ItemRect);
  742.                 ControlHDL:=ControlHandle(ItemHDL);
  743.                 HideControl(ControlHDL);
  744.                 HiliteControl(ControlHDL, DeadControl);
  745.                 DialogDefault(Dialog);
  746.                 SetupDialog(Dialog, TRUE, TRUE, TRUE);
  747.                 ModalDialog(theDialogFilter, Item);
  748.                 DisposSetUp(Dialog);
  749.                 DisposDialog(Dialog);
  750.                 YesNoDLOG:=GenericResponse(EnumValue(Item));
  751.             end; {YesNoDLOG}
  752.  
  753.         function DeleteFile;
  754.             var
  755.                 Response: GenericResponse;
  756.                 FileReply: SFReply;
  757.                 TypeList: SFTypeList;
  758.                 FileErr: OSErr;
  759.                 FileCount: INTEGER;
  760.             begin
  761.                 DeleteFile:=FALSE;
  762.                 FileCount:=-1;
  763.  
  764.                 FileReply:=DoSFGet(FileCount, TypeList, 0, 0);
  765.  
  766.                 if FileReply.good then
  767.                     begin
  768.                         Response:=YesNoDLOG('Do you really want to Delete the file "',
  769.                                                                 FileReply.fName, '"?', '');
  770.                         if Response=YesResponse then
  771.                             FileErr:=FSDelete(FileReply.fName, FileReply.vRefNum);
  772.                     end; {if FileReply.good}
  773.             end; {DeleteFile}
  774. end. {unitUtilities}
  775.